import {
  AlbumTypeEnum,
  ChainTxStateEnum,
  TokenSourceEnum,
  TokenStatusEnum,
} from '@/enums';
import { Prisma } from '@prisma/client';
import { Transform, Type } from 'class-transformer';
import {
  IsDefined,
  IsNotEmptyObject,
  ValidateIf,
  ValidateNested,
} from 'class-validator';
import { BaseDto, BaseFindDto, BaseQueryDto, WhiteListItem } from './base.dto';

export class AssetCreateDto extends BaseDto<Prisma.AssetCreateInput> {}

export class AssetUpdateDto extends BaseDto<Prisma.AssetUpdateInput> {
  @IsDefined({ message: '条件必填' })
  @IsNotEmptyObject({ nullable: false }, { message: '条件参数必填' })
  where: Prisma.AssetWhereUniqueInput;
}

export class AssetFindDto extends BaseFindDto<
  Prisma.AssetWhereUniqueInput,
  Prisma.AssetSelect
> {}

export class AssetQueryDto extends BaseQueryDto<Prisma.AssetWhereUniqueInput> {}

export class AssetHoldDto extends BaseQueryDto<Prisma.AssetWhereUniqueInput> {
  userId: number;
  assetId?: number;
  albumId?: number;
  type?: AlbumTypeEnum;
  status?: TokenStatusEnum;
}

export class AssetConsignmentDto extends BaseQueryDto<Prisma.AssetWhereUniqueInput> {
  userId: number;
  status?: TokenStatusEnum;
  albumId?: number;
}

export class AssetTokensDto extends BaseQueryDto<Prisma.AssetWhereUniqueInput> {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;
  userId: number;
}

export class AssetSaleDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;

  @IsDefined({ message: '价格必填' })
  @Transform(({ value }) => Number(value))
  price: number;

  @IsDefined({ message: '密码必填' })
  pass: string;

  userId: number;
}

export class AssetDeployDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;
}

export class AssetMintDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;
}

export class AssetBurnDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;

  @IsDefined({ message: '编号必填' })
  no: string;
}

export class AssetSyncDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;

  @IsDefined({ message: '交易状态必填' })
  txState: ChainTxStateEnum;
}

export class AssetAirdropDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;

  @IsDefined({ message: '空投记录必填' })
  @ValidateNested({ each: true })
  @Type(() => WhiteListItem)
  rows: WhiteListItem[];
}

export class AssetTargetedSaleDto {
  @IsDefined({ message: 'HASH必填' })
  hash: string;

  @IsDefined({ message: '目标ID必填' })
  @Transform(({ value }) => Number(value))
  to: number;

  @IsDefined({ message: '价格必填' })
  @Transform(({ value }) => Number(value))
  price: number;

  @ValidateIf((o) => !!o.discount)
  @Transform(({ value }) => Number(value))
  discount?: number;

  ip?: string;
}

export class AssetTransferDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;

  @IsDefined({ message: '源ID必填' })
  @Transform(({ value }) => Number(value))
  from: number;

  @IsDefined({ message: '目标ID必填' })
  @Transform(({ value }) => Number(value))
  to: number;

  @ValidateIf((o) => !!o.targets)
  targets?: number[];

  source?: TokenSourceEnum;
}

export class AssetDistributionDto extends BaseQueryDto<{
  mobile?: string;
  realname?: string;
}> {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;
}

export class AssetCirculationDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;
}

export class AssetPreDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;
}

export class AssetRegistrationDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;
}

export class AssetLockDto {
  @IsDefined({ message: '哈希值必填' })
  targets: string[];
}

export class AssetUnLockDto {
  @IsDefined({ message: '哈希值必填' })
  targets: string[];
}

export class AssetReceiveDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;

  @Transform(({ value }) => Number(value))
  addressId?: number;
}

export class AssetDestroyDto {
  @IsDefined({ message: 'ID未选择' })
  // @Transform(({ value }) => Number(value))
  ids: number[];
}
